import { defineStore } from "pinia";
import { getMenuListApi } from '@/api/modules/login'
import { getFlatMenuList, getShowMenuList,getAllBreadcrumbList } from "@/utils";


export const useAuthStore = defineStore({
    id: 'auth',
    state: (): any => ({
        authMenuList: []
    }),
    getters: {
        authMenuListGet: state => state.authMenuList,
        // 菜单权限列表 ==> 左侧菜单栏渲染，需要剔除 isHide == true
        showMenuListGet: state => getShowMenuList(state.authMenuList),
        // 菜单权限列表 ==> 扁平化之后的一维数组菜单，主要用来添加动态路由
        flatMenuListGet: state => getFlatMenuList(state.authMenuList),
        // 递归处理后的所有面包屑导航列表
        breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList)
    },
    actions: {
        async getAuthMenuList() {
            const { data }: any = await getMenuListApi();
            this.authMenuList = data.routerMenu;
        },
    }
})




